package org.example.computerdesign.service.imp;

import org.example.computerdesign.common.SendEmail;
import org.example.computerdesign.common.constants.CommonRedisKeyConstant;
import org.example.computerdesign.service.CommonService;
import org.example.computerdesign.util.RandomCodeGenerationUtil;
import org.example.computerdesign.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author 朱文权
 * */
@Service
public class CommonServiceImp implements CommonService {
    @Autowired
    private SendEmail send;
    /**
     * 发送验证码
     *
     * @param email
     */
    @Override
    public void sendCode(String email) {
        //生成6位验证码
        String code= RandomCodeGenerationUtil.generate();
        //将6位验证码存入redis
        String key= CommonRedisKeyConstant.EMAIL_REGISTER_KEY+email;
        //10分钟失效
        RedisUtil.set(key,code,60*10);
        //发送验证码
        send.sendSimpleEmail(new String[]{email},"注册验证码",code);
    }
}
